package com.magic.ch07_贪心.仓库选址;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

/**
 * created by mzk on 2020/07/19
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        int n = Integer.parseInt(br.readLine());
        int[] x = new int[n];
        String[] s = br.readLine().split(" ");
        br.close();
        for(int i = 0 ; i < n ; i++){
            x[i] = Integer.parseInt(s[i]);
        }
        Arrays.sort(x);
        int c = x[n/2];
        long ans = 0;
        for(int i = 0;i<n;i++){
            ans += Math.abs(x[i]-c);
        }
        pw.printf("%d",ans);
        pw.flush();
        pw.close();
    }
}
